package com.rankeiot.dev.mode;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import org.sagacity.sqltoy.utils.StringUtil;
@Data
public class Column {
    /*
  	<attr name="Name">村级粪污和污水处理设施设备</attr>
    <attr name="Code">Fwscl</attr>
    <attr name="ControlType">Radio</attr>
    <attr name="ID">Column-9514a407-e6d1-4876-88d1-19dfa2dbb2a4</attr>
    <attr name="MaxIDType"></attr>
    <attr name="Memo">
        <![CDATA[]]>
    </attr>
    <attr name="Options">
        <![CDATA[CodeType:WSCLSS]]>
    </attr>
    <attr name="StyleClass"></attr>
    <attr name="StyleText"></attr>
    <attr name="UIDefaultValue"></attr>
    <attr name="Verify">
        <![CDATA[]]>
    </attr>
    <attr name="DataType">1</attr>
    <attr name="ListColumnWidth">0</attr>
    <attr name="isMandatory">false</attr>
    <attr name="isMaxID">false</attr>
    <attr name="isPrimaryKey">false</attr>
    <attr name="isSearchCondition">false</attr>
    <attr name="isVisiableInForm">true</attr>
    <attr name="isVisiableInList">true</attr>
    <attr name="Length">500</attr>
    <attr name="Precision">0</attr>
     */
    private String name;
    private String code;
   //sql 数据类型
    private String type;
    //控件类型
    private String controlType;
    private String options;
    private String memo;
    private String verify;
    //java数据类型
    private String dataType;
    private boolean isMandatory;
    private boolean isPrimaryKey;
    private boolean isSearchCondition;
    private boolean isVisibleInList;
    private boolean isVisibleInForm;
    private int length;
    private int precision;
    private boolean autoIncrement;


    @JsonIgnore
    public String getField(){
        return StringUtil.toHumpStr(this.code,false);
    }
    @JsonIgnore
    public String getDict(){
        if(StringUtil.isBlank(options)){
            return null;
        }
        if(options.startsWith("dict:")){
            return options.substring(5);
        }
        return null;
    }
    @JsonIgnore
    public String getTranslate(){
        if(StringUtil.isBlank(options)){
            return null;
        }
        if(options.startsWith("translate:")){
            return options.substring(10);
        }
        return null;
    }
    @JsonIgnore
    public String getViewOpt(){
        if(StringUtil.isBlank(options)){
            return null;
        }
        if(options.startsWith("dict:")){
            return "dict=\""+options.substring(5)+"\"";
        }
        if(options.startsWith("translate:")){
            return "uri=\"system/translate/"+options.substring(10)+"\"";
        }
//        if(options.startsWith("FromTable:")){
//            return ":datas=\"options."+code+"\"";
//        }
        return null;
    }
    @JsonIgnore
    public String getOptType(){
        if(StringUtil.isBlank(options)){
            return null;
        }
        if(options.startsWith("dict:")){
            return "dict";
        }
        if(options.startsWith("translate:")){
            return "translate";
        }
//        if(options.startsWith("FromTable:")){
//            return "table";
//        }
        return null;
    }
//    @JSONField(serialize=false)
//    public String getOptData(){
//       // Options
//        if(StringUtil.isBlank(options)){
//            return null;
//        }
//        if(options.startsWith("Options:")){
//            String data=options.substring(8);
//            List<String> sb=new ArrayList<>();
//            for(String item:data.split(",")){
//
//            }
//            return "{"+String.join(",",sb)+"}";
//
//        }
//        return null;
//    }
//    public String  getViewOpts() {
////        if(options==null) {
////            return "";
////        }
////        if(options.startsWith("CodeType:")) {
////            return "";
////        }
////        if(options.startsWith("Options:")) {
////            return code+":"+toOptions()+" ";
////        }
////        if(options.startsWith("FromTable:")) {
////            return "Code:new DataSource(\""+ StrKit.firstCharToLowerCase(Parent.CRUDPrefix)+"/"+code+"\").loadData(),";
////        }
//        return "";
//    }
}
